/**
 * @Author: Ray丶X
 * @Date: 2020/3/25
 */
var http = require('http');
var url = require('url');

function start(route) {

  function onRequest(request, response) {
    // console.log(request, 'receive request');
    var pathname = url.parse(request.url).pathname;

    console.log(pathname, 'receive pathname');

    route(pathname);

    response.writeHead(200, {
      'Content-Type': 'text/plain'
    });

    response.write('create server');

    response.end();
  }

  http.createServer(onRequest).listen(8001);

}

exports.start = start;

// http.createServer(function (request, response) {
//   response.writeHead(200, {
//     'Content-Type': 'text/plain'
//   });
//
//   // response.write('day2');
//
//   response.end('day2');
//
// }).listen(8000);

console.log('Server running at http://127.0.0.1:8001/');
